package com.wtwd.device.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wtwd.device.dao.AlarmInfoMapper;
import com.wtwd.device.model.entity.AlarmInfo;
import com.wtwd.device.service.AlarmInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mjy
 * @since 2021-11-18
 */
@Service
public class AlarmInfoServiceImpl implements AlarmInfoService {

    @Autowired
    private AlarmInfoMapper alarmInfoMapper;

    @Override
    public List<AlarmInfo> getAllAlarmByDeviceId(Long deviceId) {
        return new LambdaQueryChainWrapper<>(alarmInfoMapper)
                .eq(AlarmInfo::getDeviceId, deviceId)
                .list();
    }

    @Override
    public IPage queryPage(AlarmInfo alarmInfo, Page<AlarmInfo> page) {
        return new LambdaQueryChainWrapper<>(alarmInfoMapper)
                .eq(AlarmInfo::getDeviceId, alarmInfo.getDeviceId())
                .page(page);
    }

    @Override
    public Integer save(AlarmInfo alarmInfo) {
        return alarmInfoMapper.insert(alarmInfo);
    }

    @Override
    public Integer updateAlarm(AlarmInfo alarmInfo) {
        return alarmInfoMapper.updateById(alarmInfo);
    }

    @Override
    public Integer deleteAlarm(Long id) {
        return alarmInfoMapper.deleteById(id);
    }

    @Override
    public Integer bathUpdateAlarmState(List<AlarmInfo> alarmInfos) {
       /* for (AlarmInfo alarmInfo : alarmInfos) {
            AlarmInfo alarm = new LambdaQueryChainWrapper<>(alarmInfoMapper)
                    .eq(AlarmInfo::getDeviceId, alarmInfo.getDeviceId())
                    .eq(AlarmInfo::getHour, alarmInfo.getHour())
                    .eq(AlarmInfo::getMinute, alarmInfo.getMinute())
                    .eq(AlarmInfo::getWeekRepeat, alarmInfo.getWeekRepeat())
                    .one();
            alarm.setState(alarmInfo.getState());
            rest = +(alarmInfoMapper.updateById(alarm));
        }*/
        return alarmInfoMapper.bathUpdateAlarmState(alarmInfos);
    }

}
